home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 307.adf / Samp / SAMP.h < prev    next >
C/C++ Source or Header  |  1990-01-13  |  9KB  |  381 lines

  1. /****************************************************************************
  2.    The C Include file for the dissidents' samp.library. This library reads
  3.    and writes SAMP files. Set your editor's TAB width to 3.
  4.  
  5.    Version 1.0        Dec 1989
  6.  
  7.     by Jim Fiore and Jeff Glatt
  8.  
  9. ****************************************************************************/
  10.  
  11. #ifndef SAMP_H
  12. #define SAMP_H
  13.  
  14. /* ============ SAMP.LIB ERROR CODES ============ */
  15. #define SUCCESS            0    /* Operation successful */
  16. #define LIBINUSE            1    /* Some other task is using samp.library */
  17. #define NOOPENFILE        2    /* Cannot open the file */
  18. #define NOTSAMP            3    /* Not a SAMP file */
  19. #define BADSAMP            4    /* Bad SAMP file */
  20. #define NOSUPPORT    equ    5    /* SAMP file not supported */
  21. #define OUTOFRANGE        6    /* Too few waves in the file */
  22. #define OUTOFMEM            7    /* No mem to load the next wave */
  23. #define NOMOREWAVES        8    /* No more waves in the file */
  24. #define USERABORT            9    /* Application Abort */
  25.  
  26. /*
  27. #define ID_SAMP MakeID('S','A','M','P')
  28. #define ID_NAME MakeID('N','A','M','E')
  29. */
  30.  
  31. /* ======================= The SAMP file MHDR chunk ===================== */
  32.  
  33. #define ID_MHDR MakeID('M','H','D','R')
  34.  
  35.     /* MHDR size is dependant on the size of the imbedded playMap. */
  36.  
  37. typedef struct {
  38.     UBYTE NumOfWaves,        /* The number of waves in this file */
  39.         Format,                /* # of ORIGINAL significant bits from 8-28 */
  40.         Flags,                /* Various bits indicate various functions */
  41.         PlayMode,            /* determines play MODE of the playMap */
  42.         NumOfChans,
  43.         Pad,
  44.         PlayMap[128][4];    /* a map of which wave numbers to use for
  45.                                     each of 128 possible Midi Notes. Default to 4 */
  46.    } MHDRChunk;
  47.  
  48. #define    INDEPENDANT        0
  49. #define    MULTI                1
  50. #define    STEREO            2
  51. #define    PAN                3
  52.  
  53.  
  54. /* ====================== The SAMP file BODY chunk ====================== */
  55.  
  56. #define ID_BODY MakeID('B','O','D','Y')
  57.  
  58. /* Every wave has an 80 byte waveHeader, followed by its data. The waveHeader
  59.    structure is as follows:  */
  60.  
  61. typedef struct {
  62.    ULONG  WaveSize;
  63.    USHORT MidiSampNum;
  64.    UBYTE  LoopType, InsType;
  65.    ULONG  Period, Rate, LoopStart, LoopEnd;
  66.    UBYTE  RootNote, VelStart;
  67.    USHORT VelTable[16];
  68.    ULONG  ATAKsize, RLSEsize, FATKsize, FRLSsize, USERsize;
  69.    USHORT  USERtype;
  70.    } waveHeader;
  71.  
  72. #define    SPECIFIC    0
  73. #define    VOLMOD    1
  74. #define    PERMOD    2
  75. #define    LOOPING    3
  76.  
  77.  
  78. /* ================ SAMPlib SampleHeader64 structure ============= */
  79. /* Used by the lib to load SAMP files */
  80.  
  81. struct SampleHeader64
  82. {
  83.     BYTE        *OneShotAddr;
  84.     UBYTE        Flags;            /* bit 7 on = no overlay */
  85.     UBYTE        VelStart;
  86.     USHORT    VelTable[16];
  87.     BYTE        *OneShotEnd;    /* loop start, as well */
  88.     USHORT    *TransTable;    /* points to ORIGINAL_PITCH */
  89.     USHORT    RootNote;
  90.     ULONG        LoopLength;        /* in words, bit 31 cannot be set */
  91.     UBYTE        AttackRate;        /* 0 - 255 */
  92.     UBYTE        AttackInc;        /* 1 - 64 */
  93.     UBYTE        DecayRate;        /* 1 - 255 */
  94.     UBYTE        DecayDec;        /* 1 - 64 */
  95.     UBYTE        SustLevel;        /* 0 - 64 */
  96.     UBYTE        ReleaseRate;    /* 1 - 255 */
  97.     UBYTE        ReleaseDec;        /* 1 - 64 */
  98.     UBYTE        ClipNote;
  99.     ULONG        WaveSize;            /* in bytes */
  100. };
  101.  
  102. /* ====================== For the Transpose table ==================== */
  103. /* For playback of the wave */
  104.  
  105. struct TransposeNode
  106. {
  107.     struct    TransposeNode    *Next;
  108.     struct    TransposeNode    *Prev;
  109.     ULONG        Rate;
  110.     USHORT    *Orig;
  111.     ULONG        TSize;
  112. };
  113.  
  114. #define AUDIO_HARDWARE_FUDGE .279365
  115.  
  116.  
  117. /* =================== the library's SAMPInfo structure ================ */
  118.  
  119. struct SAMPInfo
  120. {        struct FileHandle *Handle;
  121.          UBYTE SAMP[4];
  122.         ULONG FileSize;
  123.         UBYTE MHDR[4];
  124.         ULONG    MHDRsize;
  125.         UBYTE NumOfWaves,
  126.           SampleFormat,
  127.           Flags,
  128.           PlayMode,
  129.           NumOfChans,
  130.           Pad,
  131.           PlayMap[128][4];
  132.         ULONG ANNOChunk,    /* DOS Seek() offset from beginning of file to ANNO chunk */
  133.             BODYChunk,
  134.             NAMEChunk,
  135.             AUTHChunk,
  136.             COPYChunk;
  137.         APTR ATAK,
  138.             RLSE,
  139.             FATK,            /* Vector for the application's FATK routine */
  140.             FRLS,
  141.             USER,
  142.             EXTRA;
  143.         ULONG    SeekPos;
  144.         ULONG    MemType;        /* AllocMem() attributes of mem where sample data is loaded */
  145.         USHORT MaxChars,    /* Max # of chars in string buffer */
  146.             LowPer,
  147.             HighPer;
  148. };
  149.  
  150. /* ======================== Instrument types ========================= */
  151. /* You can construct the InsType field by OR'ing the family with the
  152.     class. For example,
  153.  
  154.     InsType = STRING | VIOLA_BOW;
  155. */
  156.  
  157. /* Instrument Families */
  158. #define    STRING        0x10
  159. #define    WOODWIND        0x20
  160. #define    KEYBOARD        0x30
  161. #define    GUITAR        0x40
  162. #define    VOICE            0x50
  163. #define    DRUM1            0x60
  164. #define    DRUM2            0x70
  165. #define    PERCUSSION1    0x80
  166. #define    BRASS1        0x90
  167. #define    BRASS2        0xA0
  168. #define    CYMBAL        0xB0
  169. #define    EFFECT1        0xC0
  170. #define    EFFECT2        0xD0
  171. #define    SYNTH            0xE0
  172.  
  173. /* Instrument Classes */
  174.  
  175. /* For the STRING family, the high nibble is as follows: */
  176.  
  177. #define    VIOLIN_BOW        0x1
  178. #define    VIOLIN_PLUCK    0x2
  179. #define    VIOLIN_GLIS        0x3
  180. #define    VIOLIN_TREM        0x4
  181. #define    VIOLA_BOW        0x5
  182. #define    VIOLA_PLUCK        0x6
  183. #define    VIOLA_GLIS        0x7
  184. #define    VIOLA_TREM        0x8
  185. #define    CELLO_BOW        0x9
  186. #define    CELLO_PLUCK        0xA
  187. #define    CELLO_GLIS        0xB
  188. #define    CELLO_TREM        0xC
  189. #define    BASS_BOW            0xD
  190. #define    BASS_PLUCK        0xE
  191. #define    BASS_TREM        0xF
  192.  
  193. /* For the BRASS1 family, the high nibble is as follows: */
  194.  
  195. #define    BARITONE_SAX    0x1
  196. #define    BARI_GROWL        0x2
  197. #define    TENOR_SAX        0x3
  198. #define    TENOR_GROWL        0x4
  199. #define    ALTO_SAX            0x5
  200. #define    ALTO_GROWL        0x6
  201. #define    SOPRANO_SAX        0x7
  202. #define    SOPRANO_GROWL    0x8
  203. #define    TRUMPET            0x9
  204. #define    MUTED_TRUMPET    0xA
  205. #define    TRUMPET_DROP    0xB
  206. #define    TROMBONE            0xC
  207. #define    TROMBONE_SLIDE    0xD
  208. #define    TROMBONE_MUTE    0xE
  209.  
  210. /* For the BRASS2 family, the high nibble is as follows: */
  211.  
  212. #define    FRENCH_HORN        0x1
  213. #define    TUBA                0x2
  214. #define    FLUGAL_HORN        0x3
  215. #define    ENGLISH_HORN    0x4
  216.  
  217. /* For the WOODWIND family, the high nibble is as follows: */
  218.  
  219. #define    CLARINET            0x1
  220. #define    FLUTE                0x2
  221. #define    PAN_FLUTE        0x3
  222. #define    OBOE                0x4
  223. #define    PICCOLO            0x5
  224. #define    RECORDER            0x6
  225. #define    BASSOON            0x7
  226. #define    BASS_CLARINET    0x8
  227. #define    HARMONICA        0x9
  228.  
  229. /* For the KEYBOARD family, the high nibble is as follows: */
  230.  
  231. #define    GRAND_PIANO        0x1
  232. #define    ELEC_PIANO        0x2
  233. #define    HONKYTONK        0x3
  234. #define    TOY_PIANO        0x4
  235. #define    HARPSICHORD        0x5
  236. #define    CLAVINET            0x6
  237. #define    PIPE_ORGAN        0x7
  238. #define    HAMMOND_B3        0x8
  239. #define    FARFISA_ORGAN    0x9
  240. #define    HARP                0xA
  241.  
  242. /* For the DRUM1 family, the high nibble is as follows: */
  243.  
  244. #define    KICK            0x1
  245. #define    SNARE            0x2
  246. #define    TOM            0x3
  247. #define    TIMBALES        0x4
  248. #define    CONGA_HIT    0x5
  249. #define    CONGA_SLAP    0x6
  250. #define    BRUSH_SNARE    0x7
  251. #define    ELEC_SNARE    0x8
  252. #define    ELEC_KICK    0x9
  253. #define    ELEC_TOM        0xA
  254. #define    RIMSHOT        0xB
  255. #define    CROSS_STICK    0xC
  256. #define    BONGO            0xD
  257. #define    STEEL_DRUM    0xE
  258. #define    DOUBLE_TOM    0xF
  259.  
  260. /* For the DRUM2 family, the high nibble is as follows: */
  261.  
  262. #define    TIMPANI            0x1
  263. #define    TIMPANI_ROLL    0x2
  264. #define    LOG_DRUM            0x3
  265.  
  266. /* For the PERCUSSION1 family, the high nibble is as follows: */
  267.  
  268. #define    BLOCK                0x1
  269. #define    COWBELL            0x2
  270. #define    TRIANGLE            0x3
  271. #define    TAMBOURINE        0x4
  272. #define    WHISTLE            0x5
  273. #define    MARACAS            0x6
  274. #define    BELL                0x7
  275. #define    VIBES                0x8
  276. #define    MARIMBA            0x9
  277. #define    XYLOPHONE        0xA
  278. #define    TUBULAR_BELLS    0xB
  279. #define    GLOCKENSPEIL    0xC
  280.  
  281. /* For the CYMBAL family, the high nibble is as follows: */
  282.  
  283. #define    CLOSED_HIHAT    0x1
  284. #define    OPEN_HIHAT        0x2
  285. #define    STEP_HIHAT        0x3
  286. #define    RIDE                0x4
  287. #define    BELL_CYMBAL        0x5
  288. #define    CRASH                0x6
  289. #define    CHOKE_CRASH        0x7
  290. #define    GONG                0x8
  291. #define    BELL_TREE        0x9
  292. #define    CYMBAL_ROLL        0xA
  293.  
  294. /* For the GUITAR family, the high nibble is as follows: */
  295.  
  296. #define    ELECTRIC            0x1
  297. #define    MUTED_ELEC        0x2
  298. #define    DISTORTED        0x3
  299. #define    ACOUSTIC            0x4
  300. #define    STRING_12        0x5
  301. #define    NYLON_STRING    0x6
  302. #define    POWER_CHORD        0x7
  303. #define    HARMONICS        0x8
  304. #define    CHORD_STRUM        0x9
  305. #define    BANJO                0xA
  306. #define    ELEC_BASS        0xB
  307. #define    SLAPPED_BASS    0xC
  308. #define    POPPED_BASS        0xD
  309. #define    SITAR                0xE
  310. #define    MANDOLIN            0xF
  311.  
  312. /* For the VOICE family, the high nibble is as follows: */
  313.  
  314. #define    MALE_AHH        0x1
  315. #define    FEMALE_AHH    0x2
  316. #define    MALE_OOO        0x3
  317. #define    FEMALE_OOO    0x4
  318. #define    FEMALE        0x5
  319. #define    BREATHY        0x6
  320. #define    LAUGH            0x7
  321. #define    WHISTLER        0x8
  322.  
  323. /* For the EFFECTS1 family, the high nibble is as follows: */
  324.  
  325. #define    EXPLOSION        0x1
  326. #define    GUNSHOT            0x2
  327. #define    CREAKING_DOOR    0x3
  328. #define    DOOR_SLAM        0x4
  329. #define    DOOR_CLOSE        0x5
  330. #define    SPACEGUN            0x6
  331. #define    JET_ENGINE        0x7
  332. #define    PROPELLER        0x8
  333. #define    HELOCOPTER        0x9
  334. #define    BROKEN_GLASS    0xA
  335. #define    THUNDER            0xB
  336. #define    RAIN                0xC
  337. #define    BIRDS                0xD
  338. #define    JUNGLE_NOISES    0xE
  339. #define    FOOTSTEP            0xF
  340.  
  341. /* For the EFFECTS2 family, the high nibble is as follows: */
  342.  
  343. #define    MACHINE_GUN        0x1
  344. #define    TELEPHONE        0x2
  345. #define    DOG_BARK            0x3
  346. #define    DOG_GROWL        0x4
  347. #define    BOAT_WHISTLE    0x5
  348. #define    OCEAN                0x6
  349. #define    WIND                0x7
  350. #define    CROWD_BOOS        0x8
  351. #define    APPLAUSE            0x9
  352. #define    ROARING_CROWDS    0xA
  353. #define    SCREAM            0xB
  354. #define    SWORD_CLASH        0xC
  355. #define    AVALANCE            0xD
  356. #define    BOUNCING_BALL    0xE
  357. #define    BALL_ON_BAT        0xF    /* OR CLUB */
  358.  
  359. /* For the SYNTH family, the high nibble is as follows: */
  360.  
  361. #define    SYNTH_STRINGS    0x1
  362. #define    SQUARE_WAVE        0x2
  363. #define    SAWTOOTH_WAVE    0x3
  364. #define    TRI_WAVE            0x4
  365. #define    SINE_WAVE        0x5
  366. #define    NOISE                0x6
  367.  
  368. /* ======================== SAMP.LIB ROUTINES ========================= */
  369.  
  370. struct SAMPInfo *OpenSampWrite();
  371. struct SAMPInfo *OpenSampRead();
  372. BOOL  WriteWaves(), WriteNames(), WriteMHDR(), WriteSampChunk(), WriteSampData();
  373. void  CloseSamp();
  374. void  LoadPlaymap();
  375. void  MixPlaymap();
  376. SHORT ReadWaves();
  377. USHORT *MakeTransTable();
  378. UBYTE  *SAMPErrorMsg();
  379.  
  380. #endif
  381.